(function($){
	var UpLoadHelper = function(){};
	/**
	 * 文件上传
	 * @param {String} url 接口路径
	 * @param {Object} params接口参数
	 * @param {function} success上传成功回调
	 * @param {String} filePath 文件路径
	 * @param {String} key文件参数名 例如 file
	 */
	UpLoadHelper.prototype.doUpLoads = function (success,error){
			let input = document.createElement("input")
			input.type = "file"
			input.id = "inputZq"
			input.accept = ""
			input.onchange = (event) => {  
				let file = input.files[0];
				let size =  file.size; 
				if( 20971520 <= size){
					mui.alert("上传文件不能大于20MB")
					return;
				}
				let src = window.URL.createObjectURL(file)
				var reader = new FileReader(); 
				reader.readAsDataURL(file);
				let byte = "";
				reader.onloadend = function (e) { 
					byte = e.target.result.split("base64,")[1]// console.log("333"+e.target.result)    //e.target.result就是最后的路径地址
				}; 

				let persionData = JSON.parse(localStorage.getItem("neiosUser"));
				let param = new Object;
				setTimeout(function() {
					param.fileBytes = byte;
					param.fileName = file.name;
					param.userId = persionData.userId;
					param.userName = persionData.name;
					// param.userId = "P108383";
					// param.userName = "党继平"
					// let url = "https://neom-t.cgnpc.com.cn/neios-appServer/app/common/uploadFile"//测试
					let url = "https://neom.cgnpc.com.cn/smartreport-api/neios-server/neios-server/app/common/uploadFile"//生产
					mui.neiosRequst.httpRequst(url,param,function(ret){
						success(ret)
					},function(err){
						error(err)
					})
				}, 100);
			}
			setTimeout(input.click(), 1000);
			
			
			// mui.plusReady(function () {
			//     var task = plus.uploader.createUpload( "https://neom-t.cgnpc.com.cn/neios-appServer/app/common/uploadFile",
			//     { method:"POST",priority:100 },
			//     function ( t, status ) {
			//         // 上传完成
			//         if ( status == 200 ) { 
			// 			console.log(JSON.stringify(t))
			//         } else {
			//             alert( "Upload failed: " + JSON.stringify(t) );
			//         }
			//         });
			//         task.addFile(filePath, {"fileName":'zzq'} );
			//         task.start();
			// })
	}
	
	UpLoadHelper.prototype.downLoadFile = function(param,success,error){
		mui.confirm("确认下载?",'提示',['取消','确认'],function (e) {
			if(1 == e.index){
				mui.plusReady(function () {
					plus.nativeUI.showWaiting('文件下载中...');
				})
				//let url = "https://neom-t.cgnpc.com.cn/neios-appServer/app/common/downloadFile"//测试
				 let url = "https://neom.cgnpc.com.cn/smartreport-api/neios-server/neios-server/app/common/downloadFile"//生产
				mui.ajax(url, {
					data: JSON.stringify(param),
					dataType: 'TXT', //服务器返回json数据
					type:"post", //http请求类型
					headers: {
						'Content-Type':'application/json',
						"token":"token"
					},
					timeout: "300000", 
					success: function(data) {
						success(data);
					},
					error: function(xhr, type, errorThrown) {
						if(typeof(error) == "function"){
							error(type,xhr);
						}
					}
				});
			}
		},'div')	
	}
	
	$.upLoadHelper = new UpLoadHelper();
})(mui)